package cn.bx.bid.service;

import cn.bx.bid.dao.ProfessorDao;
import cn.bx.bid.entity.Page;
import cn.bx.bid.entity.Professor;
import cn.bx.bid.entity.Project;
import cn.bx.bid.entity.WorkHistory;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

//M V C
@Service
public class ProfessorService {
	public static final int PAGE_SIZE = Page.PAGE_SIZE;

	@Resource
	ProfessorDao professorDao;


//	public int add(User u) {
//		SqlSession s = MyBatisUtil.get();
//		try {
//			UserDao userDao = s.getMapper(UserDao.class);
//			return userDao.add(u);
//		} finally {
//			s.commit();
//			MyBatisUtil.close(s);
//		}
//	}
//	public int update(User u) {
//		SqlSession s = MyBatisUtil.get();
//		try {
//			UserDao userDao = s.getMapper(UserDao.class);
//			return userDao.update(u);
//		} finally {
//			s.commit();
//			MyBatisUtil.close(s);
//		}
//	}
//	public int batchDel(long[] ids) {
//		SqlSession s = MyBatisUtil.get();
//		try {
//			UserDao userDao = s.getMapper(UserDao.class);
//			return userDao.batchDel(ids);
//		} finally {
//			s.commit();
//			MyBatisUtil.close(s);
//		}
//	}

	//增加专家
public int addprofessor(Professor professor){

	return professorDao.addprofessor(professor);
}

//修改专家信息
public  int  updataprofessor(Professor professor){
	return  professorDao.updataprofessor(professor);
}

//分页查询
	public Page<Professor> paging(int pageNo, int limit, String name, String tele,String id) {
			List<Professor> list = professorDao.search(pageNo, limit, name, tele, id);
			int total = professorDao.searchTotal(name, tele, id);
			Page<Professor> p = new Page<Professor>(total, limit, list);
			return p;
	}

	//删除
	public  int delprofessor(Long id){
	return  professorDao.delprofessor(id);
	}

	public Professor get(long id) {
	Professor  p = professorDao.get(id);
		return p;
	}
	public int batchDel(long[] ids) {

		return professorDao.batchDel(ids);
	}
    public int delHis(long id, long hisid) {

				int p = professorDao.delHis(id,hisid);
				return p;

    }

	public List<WorkHistory> getHistory(long id){
	return professorDao.getHistory(id);
	}
	public WorkHistory getOneHistory(long id){
		return professorDao.getOneHistory(id);
	}
	public int addHistory(WorkHistory w) {


			int p = professorDao.addHistory(w);
			return p;

	}

    public	int  historyupdate(WorkHistory workHistory){
	return  professorDao.historyupdate(workHistory);
	}

	public List<Project>  findProjs(long  profid) {
		List<Project> p = professorDao.findProjs(profid);
			return p;
	}

}
